package no.uials.distsys;

/**
 *
 * @author Anders
 */
public class Position implements java.io.Serializable {
    private int aisle;
    private int section;
    private int shelf;

    /**
     * Makes a new Position in the system.
     * 
     * @param aisle the aisle where the Article is placed.
     * @param section the section where the Article is placed.
     * @param shelf the shelf where the Article is placed.
     */
    public Position(int aisle, int section, int shelf) {
        this.aisle = aisle;
        this.section = section;
        this.shelf = shelf;
    }

    /**
     * Returns the aisle where the Article is located.
     * 
     * @return the aisle.
     */
    public int getAisle() {
        return aisle;
    }

    /**
     * Returns the Section where the Article is located.
     * 
     * @return the section.
     */
    public int getSection() {
        return section;
    }

    /**
     * Returns the shelf where the Article is located.
     * 
     * @return the shelf.
     */
    public int getShelf() {
        return shelf;
    }

    /**
     * Moves an Article to another aisle.
     * 
     * @param aisle the new aisle.
     */
    public void setAisle(int aisle) {
        this.aisle = aisle;
    }

    /**
     * Moves the Article to another section.
     * 
     * @param section the new section.
     */
    public void setSection(int section) {
        this.section = section;
    }

    /**
     * Moves the Article to another shelf.
     * 
     * @param shelf the new shelf.
     */
    public void setShelf(int shelf) {
        this.shelf = shelf;
    }
    
    /**
     * Repositions the Article.
     * 
     * @param aisle the new aisle.
     * @param section the new section.
     * @param shelf the new shelf.
     */
    public void reposition(int aisle, int section, int shelf) {
        this.aisle = aisle;
        this.section = section;
        this.shelf = shelf;
    }
    
    /**
     * Adds zeros in front of the number until it has reached the requested number of characters.
     * 
     * @param i the number.
     * @param length the requested length.
     * @return the number in String format.
     */
    public String addZero(int i, int length) {
        String retVal = i + "";
        while (retVal.length() < length) {
            retVal = 0 + retVal;
        }
        return retVal;
    }
    
    /**
     * Returns a String representation of the Position.
     * 
     * @return the Position as a String.
     */
    public String toString() {
        return addZero(aisle, 2) + "." + addZero(section, 2) + "." + addZero(shelf, 2);
    }
}